package com.mostka.ws.client;

import com.google.gwt.core.client.JavaScriptObject;

public class JsWebSocket extends JavaScriptObject{
	
	protected JsWebSocket() {
	}
	
	public static native JsWebSocket create(String location) /*-{
		return new WebSocket(location);
	}-*/;
	
	public final native int getReadyState() /*-{
		return this.readyState;
	}-*/;
	
	public final native int getBufferedAmount() /*-{
		return this.bufferedAmount;
	}-*/;
	
	public final native String getExtensions() /*-{
		return this.extensions;
	}-*/;
	
	public final native String getProtocol() /*-{
		return this.protocol;
	}-*/;
	
	public final native String getBinaryType() /*-{
		return this.binaryType;
	}-*/;
	
	public final native String getUrl() /*-{
		return this.url;
	}-*/;
	
	public final native void send(String message) /*-{
		return this.send(message);
	}-*/;
	
	public final native void close() /*-{
		return this.close();
	}-*/;
	
	public final native void onOpen(ConnectionHandler handler) /*-{
		this.onopen=function(event){
			handler.@com.mostka.ws.client.ConnectionHandler::onOpen(*)(event);
		};
	}-*/;
	
	public final native void onClose(ConnectionHandler handler) /*-{
		this.onclose=function(event){
			handler.@com.mostka.ws.client.ConnectionHandler::onClose(*)(event);
		};
	}-*/;
	
	public final native void onMessage(ConnectionHandler handler) /*-{
		this.onmessage=function(event){
			handler.@com.mostka.ws.client.ConnectionHandler::onMessage(*)(event);
		};
	}-*/;
	
	public final native void onError(ConnectionHandler handler) /*-{
		this.onerror=function(event){
			handler.@com.mostka.ws.client.ConnectionHandler::onError(*)(event);
		};
	}-*/;
	public static native boolean isSuported() /*-{
		return (typeof window.WebSocket == "function");
	}-*/;
	
	
}